<template>
  <div class="view-container">
    <div class="main-content">
      <div class="list-container">
        <div class="my-tabs-container">
          <div class="my-tabs">
            <el-tabs
                v-model="activeName"
                @tab-click="handleClick"
            >
              <el-tab-pane
                  label="产品线"
                  name="productLine"
              />
              <el-tab-pane
                  label="营销区域"
                  name="sellArea"
              />
            </el-tabs>
            <el-button
                v-auth="{v: ['crm:productLine:pms'],bool:activeName==='productLine'}"
                size="small"
                type="primary"
                @click="create(1)"
            >新建产品线
            </el-button>
            <el-button
                v-auth="{v: ['crm:area:pms'],bool:activeName==='sellArea'}"
                size="small"
                type="primary"
                @click="create(2)"
            >新建营销区域
            </el-button>
          </div>
        </div>
        <component
            :is="activeName"
            ref="component"
        />
      </div>
    </div>
  </div>
</template>

<script>
import {defineAsyncComponent, reactive, toRefs} from 'vue'
import {useRoute, useRouter} from 'vue-router'

export default {
  components: {
    sellArea: defineAsyncComponent(() => import('./sellArea.vue')),
    productLine: defineAsyncComponent(() => import('./productLine.vue')),
  },
  setup(props, context) {
    const route = useRoute()
    const router = useRouter()
    var datas = reactive({
      activeName: route.query.tabs || 'productLine',
      component: null,
    })
    const create = (val) => {
      if (val === 1) {
        datas.component.createProductLine()
      } else {
        datas.component.createArea()
      }
    }
    const handleClick = (tab, event) => {
      console.log(tab, event)
    }
    return {
      ...toRefs(datas),
      handleClick,
      create,
    }
  },
}
</script>

